<%@ page import="csc309.Flight" %>
<%@ page import="csc309.Validator" %>
<%

if (!Validator.validFlight(request)) {
	response.sendRedirect(request.getHeader("referer"));
	return;
}

String from = request.getParameter("from");
String to = from.equals("Toronto") ? "Montreal" : "Toronto";
int day = Integer.parseInt(request.getParameter("day"));
int month = Integer.parseInt(request.getParameter("month"));
int year = Integer.parseInt(request.getParameter("year"));

Flight f1 = new Flight(from, to, day, month, year, 10);
Flight f2 = new Flight(from, to, day, month, year, 20);

if (f1.getSeats() == 7 && f2.getSeats() == 7) {
	out.println("Sorry, no seats available");
	return;
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>MileHigh Airlines</title>
	<link rel="stylesheet" type="text/css" href="css/style.css" />
	<script type="text/javascript" src="js/validation.js"></script>
</head>
<body>

<h1>MileHigh Airlines</h1>

<form name="seats" method="post" action="processOrder.jsp" onsubmit="return validate(this)">
	
	<div id="seatsAvailable">
		<h2>Select a Seat</h2>
		<div id="flight1">
			<%=day%>/<%=month+1%>/<%=year%> at 10:00 am departing from <%=from%>
			<div class="seatSelector">
				<label><input id="test" type="radio" name="seat" value="0"
							<%=f1.isSeatTaken(1) ? "disabled" : ""%> /><span></span></label>
				<label><input type="radio" name="seat" value="1"
							<%=f1.isSeatTaken(2) ? "disabled" : ""%> /><span></span></label>
				<label><input type="radio" name="seat" value="2"
							<%=f1.isSeatTaken(3) ? "disabled" : ""%> /><span></span></label>
			</div>
		</div>
		<div id="flight2">
			<%=day%>/<%=month+1%>/<%=year%> at 8:00pm departing from <%=from%>
			<div class="seatSelector">
				<label><input type="radio" name="seat" value="3"
							<%=f2.isSeatTaken(1) ? "disabled" : ""%> /><span></span></label>
				<label><input type="radio" name="seat" value="4"
							<%=f2.isSeatTaken(2) ? "disabled" : ""%> /><span></span></label>
				<label><input type="radio" name="seat" value="5"
							<%=f2.isSeatTaken(3) ? "disabled" : ""%> /><span></span></label>
			</div>
		</div>
		<div class="error" id="seatError">You must select a seat</div>
	</div>
	
	<input type="hidden" name="from" value="<%=from%>" />
	<input type="hidden" name="day" value="<%=day%>" />
	<input type="hidden" name="month" value="<%=month%>" />
	<input type="hidden" name="year" value="<%=year%>" />
	
	<div id="billing">
		<h2>Billing Information</h2>
		<label for="firstName">First Name</label>
		<input type="text" name="firstName" />
		<div class="error" id="firstNameError">First name must consist of only letters</div>
		
		<label for="lastName">Last Name</label>
		<input type="text" name="lastName" />
		<div class="error" id="lastNameError">Last name must consist of only letters</div>
		
		<label for="ccNum">Card Number</label>
		<input type="text" name="ccNum" />
		<div class="error" id="ccNumError">Credit Card Number must be in the form <em>XXXX-XXXX-XXXX-XXXX</em></div>
		
		<label for="expMonth">Expiration Month</label>
		<input type="text" name="expMonth" />
		<div class="error" id="expMonthError">Month must be in the form <em>MM</em></div>
		
		<label for="expYear">Expiration Year</label>
		<input type="text" name="expYear" />
		<div class="error" id="expYearError">Year must be in the form <em>YY</em></div>
		
		<label for="address">Address</label>
		<input type="text" name="address" />
		<div class="error" id="addressError">Invalid characters in address. Allowed: <em>letters, numbers, ",", "."</em></div>
		
		<label for="city">City</label>
		<input type="text" name="city" />
		<div class="error" id="cityError">City must consist of only letters</div>
		
		<label for="province">Province</label>
		<input type="text" name="province" />
		<div class="error" id="provinceError">Province must consist of only letters</div>
		
		<label for="postalCode">Postal Code</label>
		<input type="text" name="postalCode" />
		<div class="error" id="postalCodeError">Postal code must be in the form: <em>A1A1A1</em></div>
	</div>
	
	<input class="blue-pill" type="submit" value="Order Ticket" />
	
</form>
</body>
</html>